<template>
  <div class="container">
    <div class="left">
      <el-button @click="viewName = 'page2'">页面2</el-button>
      <el-button @click="viewName = 'default'">页面1</el-button>
    </div>
    <div class="right">
      <!-- <keep-alive> -->
      <router-view :name="viewName"></router-view>
      <!-- </keep-alive> -->
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    viewName: {
      get() {
        return this.$store.state.routerView.viewName;
      },
      set(val) {
        this.setData({
          key: "viewName",
          data: val,
        });
      },
    },
  },
  methods: {
    ...mapMutations({
      setData: "routerView/setData",
    }),
  },
};
</script>

<style lang="less" scoped>
.container {
  display: flex;
  width: 100%;
  height: 100%;
  .left {
    width: 20%;
  }
  .right {
    border-left: 1px solid red;
    box-sizing: border-box;
    width: 80%;
  }
}
.active {
  color: pink;
}
</style>
